/* -------------------------------------- 

     Cherrypy webapp skeleton frontend

     License: LGPL
     Authors: saaj (mail@saaj.me)

   -------------------------------------- */

/**
 * Main application layout
 */
qx.Class.define("webapp.view.Layout", {
  
  extend : qx.ui.container.Composite,

  construct : function()
  {
    this.base(arguments, new qx.ui.layout.VBox());

    
    var header = new qx.ui.container.Composite(new qx.ui.layout.HBox(0, "center"));
    header.setAppearance("app-header");
    header.add(new qx.ui.basic.Label("cherrypy-webapp-skeleton"));
    this.add(header);
    
    
    var splitpane = new qx.ui.splitpane.Pane("horizontal");
    
    this._leftContainer  = this._createContainer();
    this._rightContainer = this._createContainer();
    
    splitpane.add(this._leftContainer, 1);
    splitpane.add(this._rightContainer, 1);
    this.add(splitpane, {flex : 1});
  },
  
  properties : {
    
    leftWidget : {
      check        : "qx.ui.core.Widget",
      deferredInit : true,
      apply        : "_applyLeftWidget"
    },
    
    rightWidget : {
      check        : "qx.ui.core.Widget",
      deferredInit : true,
      apply        : "_applyRightWidget"
    }
    
    
  },
  
  members : {
    
    _leftContainer  : null,
    _rightContainer : null,

    
    _createContainer : function()
    {
      var layout = new qx.ui.layout.VBox(8);
      layout.set({
        alignX : "center",
        alignY : "middle"
      });
      
      return new qx.ui.container.Composite(layout);
    },
    
    _applyLeftWidget : function(value)
    {
      this._leftContainer.removeAll();
      this._leftContainer.add(value);
    },
    
    _applyRightWidget : function(value)
    {
      this._rightContainer.removeAll();
      this._rightContainer.add(value);
    }
    
  }
  
});